import {Component, OnInit} from '@angular/core';
import {FormControl, FormGroup} from "@angular/forms";
import {BarnProduct} from "../entity/barn-product";
import {ProductService} from "../service/product.service";

@Component({
  selector: 'app-product-mine',
  templateUrl: './product-mine.component.html',
  styleUrls: ['./product-mine.component.less']
})
export class ProductMineComponent implements OnInit {


  validateForm = new FormGroup({
    productName: new FormControl(),
    enable: new FormControl('')
  })
  products: BarnProduct[] = []
  loading = false


  constructor(private productService: ProductService) {
  }


  ngOnInit(): void {
    this.search();
  }

  search() {
    this.loading = true
    const param = this.validateForm.getRawValue()
    this.productService.mine(param)
      .subscribe(value => {
        this.products = value
        this.loading = false
      }, () => this.loading = false)

  }

  resetForm() {
    this.validateForm.reset({enable: '', userId: ''})
  }

}
